package com.sangmo.fts.process.factoring.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.Formula;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.basic.validation.BuyerComValidator;
import com.sangmo.fts.basic.validation.SellerComValidator;
import com.sangmo.fts.common.IConstants;
import com.sangmo.fts.process.factoring.calculator.FfContractAmountCalculator;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "ff_contract")
@DataView
@ExtView
@Formula(value = "contractAmount", calc = FfContractAmountCalculator.class, groups = {"FfContract.search","FfContract.detail","FfWaybill.selection"})

@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class FfContract extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50,required = true, index = true, unique = true)
    private String code;

    @One(value = "buyerCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true, validators = BuyerComValidator.class)
    private Long buyerId;

    @One(value = "sellerCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true, validators = SellerComValidator.class)
    private Long sellerId;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true, index = true)
    private Date signDate;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true)
    private Date payDate;

    @One(value = "buyerConfirmDocument", target = FileUpload.class, groups = {"FfContract.search","FfContract.detail"}, fieldset = {"id","url","fileName"})
    private Long buyerConfirmDoc;

    @One(value = "sellerConfirmDocument", target = FileUpload.class, groups = {"FfContract.search","FfContract.detail"}, fieldset = {"id","url","fileName"})
    private Long sellerConfirmDoc;

    @DataField(index = true)
    private boolean buyerConfirm;

    @DataField(index = true)
    private boolean sellerConfirm;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getBuyerId() {
        return buyerId;
    }

    public void setBuyerId(Long buyerId) {
        this.buyerId = buyerId;
    }

    public Long getSellerId() {
        return sellerId;
    }

    public void setSellerId(Long sellerId) {
        this.sellerId = sellerId;
    }

    public Date getSignDate() {
        return signDate;
    }

    public void setSignDate(Date signDate) {
        this.signDate = signDate;
    }

    public Date getPayDate() {
        return payDate;
    }

    public void setPayDate(Date payDate) {
        this.payDate = payDate;
    }

    public Long getBuyerConfirmDoc() {
        return buyerConfirmDoc;
    }

    public void setBuyerConfirmDoc(Long buyerConfirmDoc) {
        this.buyerConfirmDoc = buyerConfirmDoc;
    }

    public Long getSellerConfirmDoc() {
        return sellerConfirmDoc;
    }

    public void setSellerConfirmDoc(Long sellerConfirmDoc) {
        this.sellerConfirmDoc = sellerConfirmDoc;
    }

    public boolean isBuyerConfirm() {
        return buyerConfirm;
    }

    public void setBuyerConfirm(boolean buyerConfirm) {
        this.buyerConfirm = buyerConfirm;
    }

    public boolean isSellerConfirm() {
        return sellerConfirm;
    }

    public void setSellerConfirm(boolean sellerConfirm) {
        this.sellerConfirm = sellerConfirm;
    }

    public interface IFfContractAmountCalculator {

    }
}
